package com.fau.template.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @desc 资源表
 * @author liny
 * @datetime 2015年1月12日,上午10:35:36
 */
@Entity
@Table(name = "t_resource")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class NmResource implements Serializable {

	private static final long serialVersionUID = 1717627012308300015L;

	private String id;
	private String name;		// 资源名称
	private String url;			// 资源地址
	private String pid;			// 父菜单id
	private String orderId;	// 序号
	private Integer checked;	// 是否选中 1选中、0 否
	
	private Set<NmRole> roleSet;

	public NmResource() {
	}

	public NmResource(String id) {
		this.id = id;
	}

	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "name", length = 15)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "url", length = 255)
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	@Column(name = "pid", length = 32)
	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	@Column(name = "order_id", length = 11)
	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}
	
	@Transient
	public Integer getChecked() {
		return checked;
	}

	public void setChecked(Integer checked) {
		this.checked = checked;
	}

	@ManyToMany(mappedBy = "resourceSet", fetch = FetchType.LAZY)
	@JsonIgnore
	public Set<NmRole> getRoleSet() {
		return roleSet;
	}

	public void setRoleSet(Set<NmRole> roleSet) {
		this.roleSet = roleSet;
	}

}
